﻿@model NAccounting.Models.AccountEntryListModel
@{
    ViewBag.Title = "Index";
}

<script language="javascript">
    $(function () {
        var searchUrl = '@Url.Action("GetAccountEntryByFilter", "AccountEntry")';

        $("#grid").jqGrid({
            datatype: "json",
            url: searchUrl,
            postData: {
                DateOption: function () { return $("#SelectedDateOption").val(); }
            },
            mtype: 'GET',
            rowNum: 10,
            rowList: [10, 20, 30],
            height: 275,
            pager: '#pager',
            sortname: 'Description',
            viewrecords: true,
            sortorder: "desc",
            colNames: ["id", "", "Descrição", "Lote", "LotId", "Plano de Contas", "Tipo", "Data", "Valor", "canEdit"],
            colModel: [{ name: "Id", width: 1, hidden: true, key: true },
                       { name: "actions", width: 8, resizable: false, sortable: false, align: "center" },
                       { name: "Description", width: 50, sortable: false },
                       { name: "Lot", width: 50, sortable: false },
                       { name: "LotId", width: 1, hidden: true },
                       { name: "AccountPlan", width: 80, sortable: false },
                       { name: "Type", width: 20, sortable: false },
                       { name: "Date", width: 20, sortable: false, align: "right" },
                       { name: "Value", width: 30, sortable: false, align: "right" },
                       { name: "canEdit", width: 1, hidden: true }
            ],
            autowidth: true,
            gridComplete: function () {
                var rows = $("#grid").jqGrid('getRowData');

                for (var i = 0; i < rows.length; i++) {
                    var row = rows[i];
                    var actions = "";

                    if (row['canEdit'] == "true") {
                        var address = "/AccountEntry/Edit/" + row['Id'];
                        editButton = "<button class='button-icon-edit-icon-only' onclick=\"window.location.href = '" + address + "'\">Editar</button>";
                        actions = editButton;
                    }

                    var lotLink = "<a href='/Lot/Edit/" + row['LotId'] + "'>" + row['Lot'] + "</a>"

                    $("#grid").jqGrid('setRowData', row['Id'], { actions: actions, Lot: lotLink });
                }

                environment.refreshStyles();
            }
        });

        $("#SelectedDateOption").change(function () {
            $('#grid').trigger('reloadGrid');
        });
    });
</script>

<div class="content-left">
    @Html.Partial("ContentLeftPartial")
</div>
<div class="content-right">
    <h2>Index</h2>
    <div>
        @Html.LabelFor(model => model.SelectedDateOption) @Html.DropDownListFor(model => model.SelectedDateOption, Model.DateOptions, new { @class = "searchable-combobox" })
    </div>
    <div style="margin-top:5px;">
        <table id="grid">
        </table>
        <div id="pager"></div>
    </div>
    <p>&nbsp;</p>
</div>